package com.changfang.gold_man.service.Imp;

import com.changfang.gold_man.entity.SwiperImg;
import com.changfang.gold_man.entity.WallPaper;
import com.changfang.gold_man.mapper.SwiperMapper;
import com.changfang.gold_man.service.SwiperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SwiperServiceImpl implements SwiperService {
    @Autowired
    private SwiperMapper swiperMapper;
    //查询所有图
    @Override
    public List<SwiperImg> findAll() {
        try {
            List<SwiperImg> swiperList = swiperMapper.findAll();
            return swiperList;
        }catch (Exception e){
            return null;
        }

    }
    //查询壁纸
    @Override
    public List<WallPaper> wallPaper() {
        try {
            List<WallPaper> wallPaperList = swiperMapper.wallpaper();
            return wallPaperList;
        }catch (Exception e){
            return null;
        }

    }
    //删除
    @Override
    public String delete(String imgId) {
        try {
            int imgIdInt = Integer.parseInt(imgId);
            swiperMapper.delete(imgIdInt);
            return "SUCCESS";
        }catch (Exception e){
            return "ERROR";
        }


    }
    //更新轮播图权限
    @Override
    public String updateStatus(String imgId, String status) {
        try {
            int imgIdInt = Integer.parseInt(imgId);
            swiperMapper.updateStatus(imgIdInt,status);
            return "SUCCESS";
        }catch (Exception e){
            return "ERROR";
        }

    }
    //查找可用的轮播图
    @Override
    public List<SwiperImg> findEnable() {
        try {
            List<SwiperImg> swiperList = swiperMapper.findEnable("1");
            return swiperList;
        }catch (Exception e){
            return null;
        }

    }

}
